//
//  HtmlEachOCVC.m
//  first
//
//  Created by 毕小强 on 16/11/3.
//  Copyright © 2016年 毕小强. All rights reserved.
//

#import "HtmlEachOCVC.h"
#import "ViewController.h"
@interface HtmlEachOCVC ()<UIWebViewDelegate>
@property(nonatomic,strong) UIWebView*webView;
@end

@implementation HtmlEachOCVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    self.webView.delegate=self;
    [self.view addSubview:_webView];
    
    NSURL*htmlUrl=[[NSBundle mainBundle]URLForResource:@"index.html" withExtension:nil];
    NSURLRequest*htmlUrlRequest=[NSURLRequest requestWithURL:htmlUrl];
    [_webView loadRequest:htmlUrlRequest];
}
#pragma mark UIWebViewDelegate
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    JSContext*context=[self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//    context.exceptionHandler = ^(JSContext*context1,JSValue*exceptionValue){
//        context1.exception=exceptionValue;
//    };
    [context evaluateScript:@"var arr = [3,4,'abc'];"];
    context[@"scan"] = ^() {
        NSLog(@"扫一扫");
    };
    context[@"send"] = ^(NSString*context){
        NSLog(@"%@",context);
        [[JSContext currentContext]evaluateScript:@"setBackGround('send')"];
        [[JSContext currentContext]evaluateScript:@"setColor()"];
    };
    context[@"native"] = self;
}
-(void)handleFactorialCalculateWithNumber:(id)json{
    NSLog(@"%@",json);
}
-(void)presentViewController:(NSString*)control{
    Class sec=NSClassFromString(control);
    id second=[[sec alloc]init];
    UIViewController*secVC=(UIViewController*)second;
    [self.navigationController pushViewController:secVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
